package com.ruoyi.flowable.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysButton;
import com.ruoyi.system.service.ISysButtonService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 流程按钮Controller
 *
 * @author ruoyi
 * @date 2023-03-14
 */
@RestController
@RequestMapping("/system/button")
public class SysButtonController extends BaseController
{
    @Autowired
    private ISysButtonService sysButtonService;

    /**
     * 查询流程按钮列表
     */
    @PreAuthorize("@ss.hasPermi('system:button:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysButton sysButton)
    {
        startPage();
        List<SysButton> list = sysButtonService.selectSysButtonList(sysButton);
        return getDataTable(list);
    }

    /**
     * 查询流程按钮列表
     */
    @GetMapping("/buttonList")
    public AjaxResult buttonList(SysButton sysButton)
    {
        List<SysButton> list = sysButtonService.selectSysButtonList(sysButton);
        return AjaxResult.success(list);
    }

    /**
     * 导出流程按钮列表
     */
    @PreAuthorize("@ss.hasPermi('system:button:export')")
    @Log(title = "流程按钮", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysButton sysButton)
    {
        List<SysButton> list = sysButtonService.selectSysButtonList(sysButton);
        ExcelUtil<SysButton> util = new ExcelUtil<SysButton>(SysButton.class);
        util.exportExcel(response, list, "流程按钮数据");
    }

    /**
     * 获取流程按钮详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:button:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysButtonService.selectSysButtonById(id));
    }

    /**
     * 新增流程按钮
     */
    @PreAuthorize("@ss.hasPermi('system:button:add')")
    @Log(title = "流程按钮", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysButton sysButton)
    {
        return toAjax(sysButtonService.insertSysButton(sysButton));
    }

    /**
     * 修改流程按钮
     */
    @PreAuthorize("@ss.hasPermi('system:button:edit')")
    @Log(title = "流程按钮", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysButton sysButton)
    {
        return toAjax(sysButtonService.updateSysButton(sysButton));
    }

    /**
     * 删除流程按钮
     */
    @PreAuthorize("@ss.hasPermi('system:button:remove')")
    @Log(title = "流程按钮", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysButtonService.deleteSysButtonByIds(ids));
    }
}
